//
//  TouchView.m
//  UIComprehensive
//
//  Created by lanou3g on 16/1/26.
//  Copyright © 2016年 徐强. All rights reserved.
//

#import "TouchView.h"

@implementation TouchView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    return self;
}
#pragma  mark - 触摸移动的时候会调用的方法
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"%s",__func__);
    UITouch *touch = [touches anyObject];
    //当前触摸点的位置以及前一时刻触摸点的位置
    CGPoint point1 = [touch locationInView:self];
    CGPoint point2 = [touch previousLocationInView:self];
    NSLog(@"x1 = %.2f,y1 = %.2f",point1.x,point1.y);
    NSLog(@"x2 = %.2f,y2 = %.2f",point2.x,point2.y);
    //圆跟着触摸点移动
    //移动的位置
    CGFloat dx = point1.x - point2.x;
    CGFloat dy = point1.y - point2.y;
    CGPoint center = self.center;
    self.center = CGPointMake( center.x + dx, center.y + dy );

}


@end
